package cn.cloudplug.friendsrecommend;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.PopupMenu.OnMenuItemClickListener;
import cn.cloudplug.friendsrecommend.R;
import cn.cloudplug.friendsrecommend.util.ShareUtil;

public class RaceInfoActivity extends Activity implements OnClickListener {

	private TextView tv_race_detail_title;
	private TextView tv_race_detali_content;
	private TextView tv_race_notice_content;
	private TextView tv_race_phone_number;
	private TextView tv_who_ask;
	private TextView tv_asked_date_time;
	private TextView tv_asked_question_content;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_race_info);
		setView();
	}

	private void setView() {
		ViewGroup vp = (ViewGroup) findViewById(R.id.title);
		vp.findViewById(R.id.iv_home).setOnClickListener(this);
		vp.findViewById(R.id.iv_more).setOnClickListener(this);
		findViewById(R.id.btn_sign).setOnClickListener(this);
		findViewById(R.id.tv_open_race_detail).setOnClickListener(this);
		findViewById(R.id.tv_open_race_notice).setOnClickListener(this);
		findViewById(R.id.iv_phone_call).setOnClickListener(this);
		findViewById(R.id.tv_ask_question).setOnClickListener(this);
		findViewById(R.id.iv_add_favorite).setOnClickListener(this);
		findViewById(R.id.iv_share).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.iv_home:
			startActivity(MainActivity.class);
			break;
		case R.id.iv_more:
			showMenu(v);	
			break;
		case R.id.btn_sign:
			new AlertDialog.Builder(this).setTitle("选择报名类型").setNegativeButton("个人报名", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					startActivity(PersonalSignActivity.class);
					dialog.dismiss();
				}
			}).setPositiveButton("团队报名", new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					startActivity(TeamSignActivity.class);
					dialog.dismiss();
				}
			}).create().show();
			break;
		case R.id.tv_open_race_detail:
			Toast.makeText(this, "展开赛事介绍", 0).show();
			break;
		case R.id.tv_open_race_notice:
			Toast.makeText(this, "展开全部赛事公告", 0).show();
			break;
		case R.id.iv_phone_call:
			Toast.makeText(this, "打电话", 0).show();
			break;
		case R.id.iv_add_favorite:
			Toast.makeText(this, "关注成功", 0).show();
			break;
		case R.id.iv_share:
			Toast.makeText(this, "分享", 0).show();
			break;
		case R.id.tv_ask_question:
			startActivity(AskQuestionActivity.class);
			break;
		}

	}

	private void startActivity(Class<?> clz) {
		startActivity(new Intent(this,clz));
	}

	private void showMenu(View v) {
		PopupMenu popup = new PopupMenu(this, v);
		popup.getMenuInflater().inflate(R.menu.main,popup.getMenu());
		popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
			public boolean onMenuItemClick(MenuItem item) {
				switch (item.getItemId()) {
				case R.id.action_share_race:
					Toast.makeText(RaceInfoActivity.this, "分享", 0).show();
					return true;
				case R.id.action_focus_race:
					Toast.makeText(RaceInfoActivity.this,
							"关注赛事", Toast.LENGTH_SHORT).show();
					return true;
				case R.id.action_scan:
					startActivity(new Intent(
							RaceInfoActivity.this,
							QRCodeActivity.class));
					return true;
				case R.id.action_report:
					Toast.makeText(RaceInfoActivity.this, "举报",
							Toast.LENGTH_SHORT).show();
					return true;
				}
				return false;
			}
		});
		popup.show();
		
	}

}
